import React, {Component} from 'react'
import {
    StyleSheet,
    View,
    Text,
    Button
} from 'react-native'

class WelcomePage extends Component{
    constructor(props){
        super(props)
        this.timer = null
        this.state = {
            isLogin: false
        }
    }
    componentDidMount() {
        const {navigation} = this.props
        this.timer = setTimeout(() => {
            navigation.navigate('Main')
        }, 5000)
    }
    componentWillUnmount() {
        clearTimeout(this.timer)
    }

    enterClick(){
        const {navigation} = this.props
        navigation.navigate(this.state.isLogin ? 'Main' : 'Login')
    }
    
    render(){
        return (
            <View style={style.container}>
                <Button title="点我进入App" onPress={() => this.enterClick()}></Button>
                <Text>广告之后，精彩即将呈现...</Text>
            </View>
        )
    }
}

const style = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center'
    }
})

export default WelcomePage